package com.fnzn.entranceGuard.controller.power;
import java.util.List;
import java.util.Map;
import java.util.Date;

import com.fnzn.entranceGuard.entity.power.PowerDevice;
import com.fnzn.entranceGuard.service.power.IPowerDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pig.common.constant.CommonConstant;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.github.pig.common.util.Query;
import com.github.pig.common.util.R;
import com.github.pig.common.web.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sxf
 * @since 2019-01-09
 */
@RestController
@RequestMapping("/powerDevice")
public class PowerDeviceController extends BaseController {
    @Autowired private IPowerDeviceService powerDeviceService;





    /**
     * 通过设备ID查询
     *
     * @param deviceId
     * @return PowerDevice
     */
    @GetMapping("/getPowerById")
    public R<List<PowerDevice>> getPowerById(String deviceId) {
        return new R<>(powerDeviceService.getPowerById(deviceId));
    }

    /**
    * 通过ID查询
    *
    * @param id ID
    * @return PowerDevice
    */
    @GetMapping("/{id}")
    public R<PowerDevice> get(@PathVariable Integer id) {
        return new R<>(powerDeviceService.selectById(id));
    }


    /**
    * 分页查询信息
    *
    * @param params 分页对象
    * @return 分页对象
    */
    @RequestMapping("/page")
    public Page page(@RequestParam Map<String, Object> params) {
        params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
        return powerDeviceService.selectPage(new Query<>(params), new EntityWrapper<>());
    }

    /**
     * 添加
     * @param  powerDevice  实体
     * @return success/false
     */
    @PostMapping
    public R<Boolean> add(@RequestBody PowerDevice powerDevice) {
        return new R<>(powerDeviceService.insert(powerDevice));
    }

    /**
     * 删除
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable Integer id) {
        PowerDevice powerDevice = new PowerDevice();
        powerDevice.setId(id);
        return new R<>(powerDeviceService.updateById(powerDevice));
    }

    /**
     * 编辑
     * @param  powerDevice  实体
     * @return success/false
     */
    @PutMapping
    public R<Boolean> edit(@RequestBody PowerDevice powerDevice) {
        return new R<>(powerDeviceService.updateById(powerDevice));
    }
}
